package com.sdjzu.wangfuying.androidbluetooth;

import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ToggleButton;

public class MainActivity extends AppCompatActivity {

    private static final int REQUEST_ENABLE = 6;
    private static final int REQUEST_DISABLE = 7;

    private Button btn_server = null;
    private Button btn_client = null;
    private ToggleButton btn_status = null;

    // bt
    private BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn_server = (Button) findViewById(R.id.activity_main_btn_server);
        btn_client = (Button) findViewById(R.id.activity_main_btn_client);
        btn_status = (ToggleButton) findViewById(R.id.activity_main_btn_bt);

        btn_client.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                startActivity(intent);
            }
        });
        btn_server.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                startActivity(intent);
            }
        });
        btn_status.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                startActivity(intent);
            }
        });
        btn_status.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                startActivity(new Intent(Settings.ACTION_BLUETOOTH_SETTINGS));
            }
        });

    }

    @Override
    protected void onResume() {
        super.onResume();
        updateStatusText();
    }

    private void updateStatusText() {
        if (mBluetoothAdapter.isEnabled()) {
            btn_status.setChecked(true);
        } else {
            btn_status.setChecked(false);
        }
    }
}
